var app = angular.module('conversionTool', []);

app.controller('loginCtrl', [ '$scope', '$http', function($scope, $http) {

	$scope.login = function() {

		if ($scope.email == undefined) {
			$scope.msg = "Please enter the right email address";
			return false;
		} 
		else if ($scope.email.length == 0) {
			$scope.msg = "Email address is empty";
			return false;
		} 
		else if ($scope.password.length == 0) {
			$scope.msg = "Password can not be empty";
			return false;
		}
		else {
		$http.post('/rest/account/login', {
			"email" : $scope.email,
			"password" : $scope.password

		}).success(function(data) {

			if (data == true) {
				location.href = "/"
			} else {
				$scope.email = "";
				$scope.password = "";
				$scope.msg = "The username or passowrd error!";
			}

		}).error(function(data) {

			console.log(data);
		});

	}
	

	$scope.register = function() {

		// go to register page

		location.href = "register";
	}
	}

} ]);